import { computed, toRef } from 'vue';
import { useStore } from 'vuex';
import Cookies from 'js-cookie';
import { repairactions } from '@/consts/repairorder.consts';
import { examRpairOrderAction } from '@/setup/maintenanceteam/FunctionForUserExam';
export default function useMaintenanceOrderConfigSetup (props) {
    const propKey = props.orderItem ? 'orderItem' : 'repairData';
    const orderItem = toRef(props, propKey);
    // 状态：1：待处理、2：处理中、3：待评价、4：已完成
    const store = useStore();
    const userinfo = store.state.userinfo;
    const {
        // 设备档案
        view_device_profile,
        // 编辑
        edit,
        // 接单
        accept,
        // 派工
        dispatch,
        // 转派
        transfer,
        // 处理
        deal,
        // 评价链接
        // copy_evaluation_link,
        // 邀请评价
        invite_to_valuate,
        // 记录详情
        record,
        // 评价
        evaluate
    } = repairactions;
    // 是否为员工
    const isStaff = computed(() => {
        return (
            userinfo &&
            userinfo.roles &&
            userinfo.roles.length > 0
        );
    });
    // 进度百分比值
    const procRate = computed(() => {
        return (orderItem.value.status / 4) * 100;
    });
    // 进度百分比文本
    const procRateTxt = computed(() => {
        return orderItem.value.status + '/4';
    });

    // 判断与我相关
    const isShowRelatedToMeTag = computed(() => {
        return userinfo && orderItem.value.administrator === userinfo.username;
    });

    // 判断显示评价按钮
    const isShowPingJiaBtn = computed(() => {
        const type = Cookies.get('setquerytype');
        const queryPhone = type === 'phone' ? Cookies.get('repairphone') : undefined;

        return examRpairOrderAction(evaluate, orderItem.value, userinfo, queryPhone);
    });
    const isshowdevicedetail = computed(() => {
        return examRpairOrderAction(view_device_profile, orderItem.value, userinfo) && orderItem.value.manufacturecode !== '';
    });

    // 判断显示接单按钮
    const isShowJieDanBtn = computed(() => {
        return examRpairOrderAction(accept, orderItem.value, userinfo);
    });

    // 判断显示派单按钮
    const isShowPaiDanBtn = computed(() => {
        return examRpairOrderAction(dispatch, orderItem.value, userinfo);
    });
    // 判断显示转派按钮
    const isShowZhuanPaiBtn = computed(() => {
        return examRpairOrderAction(transfer, orderItem.value, userinfo);
    });
    // 判断显示记录按钮
    const isShowJiLuBtn = computed(() => {
        return examRpairOrderAction(record, orderItem.value, userinfo);
    });
    // 邀请评价
    const isShowInvitePinjiaBtn = computed(() => {
        return examRpairOrderAction(invite_to_valuate, orderItem.value, userinfo);
    });
    // 判断显示处理按钮
    const isShowdealBtn = computed(() => {
        return examRpairOrderAction(deal, orderItem.value, userinfo);
    });
    // 判断显示编辑按钮
    const isShoweditBtn = computed(() => {
        return examRpairOrderAction(edit, orderItem.value, userinfo);
    });
    return {
        isStaff,
        procRate,
        procRateTxt,
        isShowRelatedToMeTag,
        isShowPingJiaBtn,
        isShowJieDanBtn,
        isShowPaiDanBtn,
        isShowZhuanPaiBtn,
        isShowJiLuBtn,
        isShowInvitePinjiaBtn,
        isshowdevicedetail,
        isShowdealBtn,
        isShoweditBtn
    };
}
